package com.noyes4j.ota.controller;

import com.noyes4j.common.core.controller.BaseController;
import com.noyes4j.common.core.domain.R;
import com.noyes4j.common.core.page.TableDataInfo;
import com.noyes4j.common.log.annotation.OperLog;
import com.noyes4j.common.log.enums.BusinessType;
import com.noyes4j.common.utils.poi.ExcelUtil;
import com.noyes4j.ota.domain.SysUpdatePlan;
import com.noyes4j.ota.service.ISysUpdatePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 升级计划Controller
 *
 * @author noyes4j
 * @date 2021-01-29
 */
@Controller
@RequestMapping("/update/plan")
public class SysUpdatePlanController extends BaseController
{
    private String prefix = "update/plan";

    @Autowired
    private ISysUpdatePlanService sysUpdatePlanService;

    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询升级计划列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysUpdatePlan sysUpdatePlan)
    {
        startPage();
        List<SysUpdatePlan> list = sysUpdatePlanService.selectSysUpdatePlanList(sysUpdatePlan);
        return getDataTable(list);
    }

    /**
     * 导出升级计划列表
     */
    @PostMapping("/export")
    @ResponseBody
    public R export(SysUpdatePlan sysUpdatePlan)
    {
        List<SysUpdatePlan> list = sysUpdatePlanService.selectSysUpdatePlanList(sysUpdatePlan);
        ExcelUtil<SysUpdatePlan> util = new ExcelUtil<SysUpdatePlan>(SysUpdatePlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 新增升级计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存升级计划
     */
    @OperLog(title = "升级计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public R addSave(SysUpdatePlan sysUpdatePlan)
    {
        return toAjax(sysUpdatePlanService.insertSysUpdatePlan(sysUpdatePlan));
    }

    /**
     * 修改升级计划
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysUpdatePlan sysUpdatePlan = sysUpdatePlanService.selectSysUpdatePlanById(id);
        mmap.put("sysUpdatePlan", sysUpdatePlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存升级计划
     */
    @OperLog(title = "升级计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public R editSave(SysUpdatePlan sysUpdatePlan)
    {
        return toAjax(sysUpdatePlanService.updateSysUpdatePlan(sysUpdatePlan));
    }

    /**
     * 删除升级计划
     */
    @OperLog(title = "升级计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public R remove(String ids)
    {
        return toAjax(sysUpdatePlanService.deleteSysUpdatePlanByIds(ids));
    }
}